#ifndef __CREATURE_H__
#define __CREATURE_H__

#include "cocos2d.h"
#include "GameObj.h"
#include "HpBar.h"
#include "BulletManager.h"

using namespace cocos2d;

#define CREATURE_CREATE_FUNC(__TYPE__) \
static __TYPE__* create() \
{ \
    __TYPE__ *pRet = new __TYPE__(); \
    if (pRet && pRet->init()) \
    { \
        pRet->autorelease(); \
		pRet->afterInit(); \
        return pRet; \
    } \
    else \
    { \
        delete pRet; \
        pRet = NULL; \
        return NULL; \
    } \
}

#define CC_SYNTHESIZE_PROTECTED(varType, varName, funName)\
protected: varType varName;\
protected: virtual varType get##funName(void) const { return varName; }\
protected: virtual void set##funName(varType var){ varName = var; }

class Creature : public GameObj 
{
	typedef enum {
		CREATURE_STATE_NORMAL,
		CREATURE_STATE_SHOOT,
		CREATURE_STATE_DYING,
		CREATURE_STATE_DEAD,
		NUM_OF_STATE,
	} ECreatureState;

	// Creature
	CC_SYNTHESIZE_PROTECTED(CCSprite*, d_creatureSprite, CreatureSprite)
	CC_SYNTHESIZE_PROTECTED(ECreatureState, d_creatureState, CreatureState)

	// type
	CC_SYNTHESIZE(OBJ_TYPE, d_objType, ObjType)

	// bullet
	CC_SYNTHESIZE(BULLET_TYPE, d_bulletType, BulletType)
	CC_SYNTHESIZE(float, d_bulletSpeed, BulletSpeed)
	CC_SYNTHESIZE(float, d_bulletDamage, BulletDamage)
	CC_SYNTHESIZE_PROTECTED(float, d_shootInterval, ShootInterval)
	CC_SYNTHESIZE(int, d_money, Money)
	
	// hp
	CC_SYNTHESIZE(bool, d_hasHpBar, HasHpBar)
	CC_SYNTHESIZE_PROTECTED(HpBar*, d_hpBar, HpBar)
	CC_SYNTHESIZE_PROTECTED(float, d_maxHP, MaxHP)
	CC_SYNTHESIZE_PROTECTED(float, d_hp, HP)

	// shoot and hit

public:
	~Creature(void);
	CREATURE_CREATE_FUNC(Creature);  
	virtual bool init();
	virtual void afterInit();

	// Creature
	virtual bool isLive() {return (d_creatureState != CREATURE_STATE_DYING && d_creatureState != CREATURE_STATE_DEAD);}

	// shoot and hit
	virtual bool hit(float damage);
	virtual CCRect getHitRect();

	void startShoot(bool firstShoot);
	virtual void stopShoot();
	//virtual void onUpdrade();

protected:
	BulletManager* d_bulletManager;
	int d_actionTintTag;
	
	// Creature
	virtual void dead(CCNode* sender);
	virtual void onDead() {};
	virtual float onHit(float damage);

	// shoot and hit
	virtual void shoot(float dt) {};

	virtual CCFiniteTimeAction* getDieAction();

private:
};

#endif // __CREATURE_H__

